#coding:utf-8
__author__ = 'admin'

from ipip import IP
import os

current_dir = os.path.dirname(__file__)
IP.load(current_dir + "/ipdb.dat")


def get_ip_info(ip):
    result = IP.find(ip).split("\t")
    result = [i for i in result if i.strip()]
    if result:
        buff = ''
        for _i,_v in enumerate(result):
            if _i:
                if result[_i-1] != _v:
                    buff += (" "+ _v)
                else:
                    break
            else:
                buff += _v
        return buff
    else:
        return '未知'


if __name__ == '__main__':
    print get_ip_info("127.0.0.1")
    print get_ip_info("202.102.224.68")
    print get_ip_info("218.28.185.19")